<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Teacher extends Base{
    //PC导师团队
    public function allteacher(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $teachers=Db::name('teacher')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($teachers){
                return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pallteacher(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $teachers=Db::name('teacher')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $teachers=Db::name('teacher')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC老师分类
    public function teachercate(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $teachercate=Db::name('tcate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($teachercate){
                return json(['code' => 200, 'msg' => '成功！','data'=>$teachercate]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pteachercate(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $teachercate=Db::name('tcate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachercate){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachercate]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $teachercate=Db::name('tcate')->where('type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachercate){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachercate]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC分类--老师
    public function cateteacher(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cate_id"))){
            $cate_id=input("param.cate_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出分类id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $teachers=Db::name('teacher')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($teachers){
                return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pcateteacher(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cate_id"))){
            $cate_id=input("param.cate_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出分类id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $teachers=Db::name('teacher')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $teachers=Db::name('teacher')->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //导师详情
    public function teacherdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $detail=Db::name('teacher')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
            if($detail){
                return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //老师--课程
    public function teachercourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.teacher_id"))){
            $teacher_id=input("param.teacher_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出老师id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $courses=Db::name('course')->where('teacher_id',$teacher_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($courses){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$courses]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $courses=Db::name('course')->where('teacher_id',$teacher_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($courses){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$courses]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
}